﻿/* Write a method that returns the last digit of given integer as an English word. 
 * Examples: 512  "two", 1024  "four", 12309  "nine".
 */




using System;

class LastDigit
{
    static void Main()
    {
        int number;

        bool iProvided = false;
        do
        {
            if (iProvided == true) Console.WriteLine("Error!: Invalid input. Please enter an integer. \r\nValid range: {0} - {1}", Int32.MinValue, Int32.MaxValue);
            else iProvided = true;
            Console.Write("Enter first number: ");
        } while (Int32.TryParse(Console.ReadLine(), out number) == false);

        string lastDigit = GetLastDigit(number);
        Console.WriteLine("The last digit in the number {0} is: {1}", number, lastDigit);
    }

    private static string GetLastDigit(int number)
    {
        //get last digit
        string numberstring = number.ToString();
        numberstring = numberstring.Substring(numberstring.Length - 1, 1);
        
        //convert to a "word-digit"
        string digit = null;
        switch (numberstring)
        {
            case "0":
                digit = "zero";
                break;
            case "1":
                digit = "one";
                break;
            case "2":
                digit = "two";
                break;
            case "3":
                digit = "three";
                break;
            case "4":
                digit = "four";
                break;
            case "5":
                digit = "five";
                break;
            case "6":
                digit = "six";
                break;
            case "7":
                digit = "seven";
                break;
            case "8":
                digit = "eight";
                break;
            case "9":
                digit = "nine";
                break;
        }
        return digit;

    }
}
